<?php
/**
 * Created by PhpStorm.
 * User: SQK
 * Date: 2018/8/24
 * Time: 10:19
 */
namespace app\blog\controller;
use app\blog\model\IntroduceModel;
use cmf\controller\AdminBaseController;
use think\Validate;

class IntroduceController extends AdminBaseController
{
    /**
     * 公司简介首页
     */
    public function index(){
        //获取公司记录
        $i          = new IntroduceModel();
        $rest       = $i->getMsg();

        if($rest == ''){
            $rest['content'] = '';
            $rest['name'] = '';
        }else{
            $content    = cmf_replace_content_file_url(htmlspecialchars_decode($rest['content']));//转换
            $rest['content'] = $content;
        }
        $this->assign('rest',$rest);
        return $this->fetch('add');
    }
    /**
     * 添加/更改公司简介
    */
    public function addPost(){
        $rest = $this->request->param();
        //验证
        $validate = new Validate([
            'name'     => 'require',
            'content'  => 'require',
        ]);
        $validate->message([
            'name.require'  =>'标题不能为空',
            'content.require'   => '内容不能为空',
        ]);
        if(!$validate->check($rest)){
            $this->error($validate->getError());
        }
        $i = new IntroduceModel();
        $rest = $i->addPost($rest);
        if($rest != false){
            $this->success('操作成功！');
        }else{
            $this->success('操作失败！');
        }
    }
}